package engineDJW.entities {
	
	import engineDJW.map.GameMap;
	import engineDJW.utils.QuickMath;
	import flash.display.Sprite;
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;
	
	/**
	 * ...
	 * @author Dale J Williams
	 */
	public class Entity extends Sprite {
		
		protected var _map		:GameMap;		
		protected var _bounds	:Rectangle;
		
		public function Entity() {}
		
		public function start():void {}
		
		public function stop():void {}
		
		public function update():void { 
			_bounds = getBounds(map);
		}
		
		public function distanceTo($x:Number, $y:Number):Number {
			var dX:Number = $x - x;
			var dY:Number = $y - y;
			return Math.sqrt(dX * dX + dY * dY);
		}
		
		public function angleTo($x:Number, $y:Number):Number {
			return Math.atan2(y - $y, x - $x) * QuickMath.DEGREES - 90;
		}
		
		public function get map():GameMap { return _map; }		
		public function set map(value:GameMap):void {
			_map = value;
			if (value) start();
			else stop();
		}
		
		public function get bounds():Rectangle {
			if (!_bounds) _bounds = getBounds(map);
			return _bounds; 
		}
		
	}

}